package corp.edu.amadeus.web.listener;

import javax.servlet.ServletContextEvent;
import javax.servlet.ServletContextListener;
import org.apache.log4j.Logger;
import corp.edu.amadeus.core.spring.BeanLocator;
import java.util.ArrayList;
import java.util.List;
import corp.edu.amadeus.commons.Constants;
import java.io.File;

public class AppLoaderListener implements ServletContextListener {

    private static Logger log = Logger.getLogger(AppLoaderListener.class);

    public void contextDestroyed(ServletContextEvent arg0) {
        // TODO Auto-generated method stub

    }

    public void contextInitialized(ServletContextEvent arg0) {
        // TODO Auto-generated method stub
    	log.debug("+++++++++++++++++++++++++++++++++++++++");
    	log.debug("---------- LOADING AMADEUS CONFIGURATION ....");
    	Constants.APP_BASE = arg0.getServletContext().getRealPath(File.separator);
    	Constants.MULTIMEDIA_REPO = Constants.APP_BASE +
    		File.separator +  Constants.MULTIMEDIA_FOLDER_NAME;
    	System.setProperty("amadeus.multimedia_repo_path", Constants.MULTIMEDIA_REPO);
    	String appl_context = arg0.getServletContext().getInitParameter("appContextConfigLocation");
    	List<String> spring_config_files = new ArrayList<String>();
    	spring_config_files.add(appl_context);
    	BeanLocator.configure(spring_config_files, true);
    }

}